Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lix: only use LTO with GCC #353576

Merged
merged 1 commit into from
Dec 7, 2024
Merged

lix: only use LTO with GCC #353576

merged 1 commit into from
Dec 7, 2024

Conversation

lilyball
Copy link
Member

@lilyball lilyball commented Nov 4, 2024

Enabling LTO causes test failures when compiling for x86_64-darwin (at least under Rosetta 2). The Nix package only enables LTO when using GCC, so we'll copy that for now. I don't feel safe leaving it on for aarch64-darwin unless we can understand why it's failing on x86_64-darwin in case this is an indication of UB.

Fixes #337036.

I am making my contributions to this project solely in my personal capacity and am not conveying any rights to any intellectual property of any third parties.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin (under Rosetta)
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Enabling LTO causes test failures when compiling for x86_64-darwin (at
least under Rosetta 2). The Nix package only enables LTO when using GCC,
so we'll copy that for now. I don't feel safe leaving it on for
aarch64-darwin unless we can understand why it's failing on
x86_64-darwin in case this is an indication of UB.

Fixes NixOS#337036.
@@ -190,7 +190,7 @@ stdenv.mkDerivation {
[
# Enable LTO, since it improves eval performance a fair amount
# LTO is disabled on static due to strange linking errors
(lib.mesonBool "b_lto" (!stdenv.hostPlatform.isStatic))
(lib.mesonBool "b_lto" (!stdenv.hostPlatform.isStatic && stdenv.cc.isGNU))
Copy link
Contributor

@JohnRTitor JohnRTitor Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we disable it for Darwin instead?

Clang LTO on Linux should be fine.

And add a comment there why its disabled on Darwin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested it? I would suspect it is more likely to be LLVM exposing UB than a Darwin issue. And the Nix derivation uses isGNU here.

Copy link
Contributor

@JohnRTitor JohnRTitor Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried building lix from master with clangStdenv and it built fine. (x86_64-linux)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. What about with libc++?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does work if that's what you are asking:

❯  nix build --impure --expr '(builtins.getFlake "github:nixos/nixpkgs/master").legacyPackages."${builtins.currentSystem}".libcxx.override {stdenv = (builtins.getFlake "github:nixos/nixpkgs/master").legacyPackages."${builtins.currentSystem}".clangStdenv;}' --print-out-paths 
/nix/store/nqpv4xbh5zqnvfn80702gahiklxxjcr3-libcxx-18.1.8

PS: if you have a shorthand for these overrides in cli, let me know!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what in the hell. maybe we have a missing include but I'm guessing those sys constants are just broken. (though libcxxStdenv is SURELY not using an alternative libc right? just libc++?)

it may also be broken toolchain on the nixpkgs side for all i know, like this release blocker for lix 2.92: #177129

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does seem to only be a missing include. Sent a patch upstream in https://gerrit.lix.systems/c/lix/+/2286

Using this override still fails when linking with things like the aws-sdk though (probably because they're using glibc?), and being a bit more forceful with libcxx usage like so

let
  pkgs = import <nixpkgs> {
    config = {
      replaceStdenv = { pkgs }: pkgs.libcxxStdenv;
    };
    overlays = [ ];
  };
in

pkgs.lix

results in the always fun error: infinite recursion encountered, so I don't think we can determine whether this is a libcxx or Darwin issue just yet

I'm inclined to say we should change this to stdenv.cc.libcxx != null for now, as that would cover Darwin and the possibly broken (and currently un-evaluatable) libcxx Linux build -- which can always be revisited later

Also let me know if there's anything I can help with to get this merged. Would love to see a fix after all this time :)

Copy link
Member

@lf- lf- Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe there is a libcxxStdenvPackages somewhere that is a nixpkgs staged from libcxxStdenv but yeah you can't really mix libc++ and libstdc++ in one binary at least if you're linking c++ symbols between them.

if this pr is acceptable i can just like, merge it. i have commit rights. i think it's more important that lix works than that it has LTO in all configurations possible (including weird ones) given that iirc LTO doesn't make that huge a difference anyway.

Copy link
Member

@winterqt winterqt Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's more important that lix works than that it has LTO in all configurations possible

Agreed.

I'm inclined to say we should change this to stdenv.cc.libcxx != null for now, as that would cover Darwin and the possibly broken (and currently un-evaluatable) libcxx Linux build -- which can always be revisited later

Also agreed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this pr is acceptable

I'd say it 100% is. My suggestions were by no means a blocker, just a way to hopefully get things going

i believe there is a libcxxStdenvPackages somewhere that is a nixpkgs staged from libcxxStdenv

TIL that is pkgsLLVM...I thought that used clangStdenv. Time to build :)
image

@JohnRTitor
Copy link
Contributor

@ofborg build lix

Copy link
Contributor

@JohnRTitor JohnRTitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builds on both x86_64-darwin and aarch64-darwin on Nix communtiy builder.

@eilvelia eilvelia mentioned this pull request Nov 4, 2024
13 tasks
@ofborg ofborg bot requested a review from Qyriad November 4, 2024 18:48
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Nov 4, 2024
@FliegendeWurst FliegendeWurst added the 6.topic: darwin Running or building packages on Darwin label Dec 6, 2024
Copy link
Member

@getchoo getchoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 353576


x86_64-darwin

✅ 10 packages built:
  • lix (lixVersions.latest ,lixVersions.lix_2_91 ,lixVersions.stable)
  • lix.dev (lixVersions.latest.dev ,lixVersions.lix_2_91.dev ,lixVersions.stable.dev)
  • lix.devdoc (lixVersions.latest.devdoc ,lixVersions.lix_2_91.devdoc ,lixVersions.stable.devdoc)
  • lix.doc (lixVersions.latest.doc ,lixVersions.lix_2_91.doc ,lixVersions.stable.doc)
  • lix.man (lixVersions.latest.man ,lixVersions.lix_2_91.man ,lixVersions.stable.man)
  • lixVersions.lix_2_90
  • lixVersions.lix_2_90.dev
  • lixVersions.lix_2_90.devdoc
  • lixVersions.lix_2_90.doc
  • lixVersions.lix_2_90.man

aarch64-darwin

✅ 10 packages built:
  • lix (lixVersions.latest ,lixVersions.lix_2_91 ,lixVersions.stable)
  • lix.dev (lixVersions.latest.dev ,lixVersions.lix_2_91.dev ,lixVersions.stable.dev)
  • lix.devdoc (lixVersions.latest.devdoc ,lixVersions.lix_2_91.devdoc ,lixVersions.stable.devdoc)
  • lix.doc (lixVersions.latest.doc ,lixVersions.lix_2_91.doc ,lixVersions.stable.doc)
  • lix.man (lixVersions.latest.man ,lixVersions.lix_2_91.man ,lixVersions.stable.man)
  • lixVersions.lix_2_90
  • lixVersions.lix_2_90.dev
  • lixVersions.lix_2_90.devdoc
  • lixVersions.lix_2_90.doc
  • lixVersions.lix_2_90.man

@getchoo getchoo added 12.approvals: 1 This PR was reviewed and approved by one reputable person backport release-24.11 Backport PR automatically labels Dec 7, 2024
@lf- lf- merged commit ff797c2 into NixOS:master Dec 7, 2024
37 checks passed
@nixpkgs-ci
Copy link
Contributor

nixpkgs-ci bot commented Dec 7, 2024

Successfully created backport PR for release-24.11:

lf- pushed a commit to lix-project/lix that referenced this pull request Dec 9, 2024
Per `seccomp(2)`, this header defines the `SYS_*` constants used

Found in NixOS/nixpkgs#353576

Change-Id: I64ebc5513c53500b7a9012eaa664c2e59f49ceac
@lilyball lilyball deleted the push-tutnmmymvtxt branch December 14, 2024 00:32
@getchoo getchoo mentioned this pull request Jan 20, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin 10.rebuild-darwin: 1-10 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux 12.approvals: 1 This PR was reviewed and approved by one reputable person backport release-24.11 Backport PR automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure: lix on x86_64-darwin
8 participants